// 数据渲染

class shuju{
    constructor(ops){
        this
    }
}
const oGoodsList = document.querySelector(".goodsList")
ajax("http://localhost:3000/api",res=>{
    res = JSON.parse(res).msg;
    console.log(res);

    let str = "";
    res.forEach(val=>{
        str += `<div class="box" index="${val.proId}">
                    <a href="./detail.html?id=${val.proId}">
                        <img src="${val.img}" alt="">
                        <p>${val.proName}</p>
                        <span>${val.price}</span>
                    </a>
                    <input type="button" class="add" value="加入购物车">
                </div>`
    })
    oGoodsList.innerHTML = str;

},{
    type:"getMsg"
})







function ajax(url, callback, data){
    let str = "";
    for(let i in data){
        str += `${i}=${data[i]}&`
    }
    url += "?" + str;
    const xhr = new XMLHttpRequest();
    xhr.open("get",url)
    xhr.onload = function(){
        if(xhr.status === 200){
            callback(xhr.responseText)
        }
    }
    xhr.send();
}



